package com.example.demo.controller;

import com.example.demo.dao.UserDao;
import com.example.demo.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@RestController
public class UserController {

    @Autowired
    private UserDao userDao;

    @RequestMapping("/login")
    public Object login(User user, HttpSession session) {
        User user1 = userDao.getByWhere(user);
        if (user1 == null) {
            return "FAIL";
        }
        session.setAttribute("USER_ID", user1.getId());
        return "OK";
    }
    @RequestMapping("/register")
    public Integer add(User user){
        user.setState(1);
        return userDao.add(user);
    }

}
